#pragma once
#include<iostream>
#include<unistd.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<arpa/inet.h>
#include<netinet/in.h>
#include<cstdlib>
#include<cstring>

#define LONG 5
using namespace std;
class Socket{
    public:
        Socket()
        {}
        static void Sock(int& listen_sock)
        {
            listen_sock=socket(AF_INET,SOCK_STREAM,0);
            if(listen_sock<0){
                cerr<<"socken error"<<endl;
                exit(1);
            }
            cout<<"socken success"<<endl;
        }
        static void Bind(int listen_sock,int port)
        {
            struct sockaddr_in own;
            memset(&own,0,sizeof(own));
            own.sin_family=AF_INET;
            own.sin_port=htons(port);
            own.sin_addr.s_addr=INADDR_ANY;
            if(bind(listen_sock,(struct sockaddr*)&own,sizeof(own))<0){
                cerr<<"bind error"<<endl;
                exit(2);
            }
            cout<<"bind success"<<endl;
        }
        static void Listen(int listen_sock)
        {
            if(listen(listen_sock,LONG)<0){
                cerr<<"listen error"<<endl;
                exit(3);
            }
            cout<<"listen success"<<endl;
        }
        ~Socket(){}
};

